package ysf.com.simplediffculty;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
 * 二十七
 * 给定一个数组找到数组中重复的元素并将其重复的元素全部删除后,返回新的数组对象
 *
 * @author ysf
 * @date 2021/8/16 18:23
 */
public class TwentySeven {

    public static void main(String[] args) {
        Integer[] nums = {1, 2, 3, 2, 4, 4,7,8,9,2};
        deleteDuplicate(nums);
    }

    public static void deleteDuplicate(Integer[] nums) {
        List<Integer> list = Arrays.asList(nums);
        System.out.println(list);
        HashSet<Integer> set = new HashSet<>();
        List<Integer> repeatlist = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Integer value = list.get(i);
            if (set.contains(value)) {
                repeatlist.add(value);
            } else {
                set.add(value);
            }
        }
        List<Integer> finalList = new ArrayList<>();
        System.out.println(repeatlist);
        for (Integer l : list) {
            if(!repeatlist.contains(l)){
                finalList.add(l);
            }
        }
        System.out.println(finalList);

    }


}
